import {Component, OnInit, ViewContainerRef} from '@angular/core';
import {BakeRecord} from '../../../../model/BakeRecord';
import {NzModalService} from 'ng-zorro-antd/modal';
import {BakerecordeditComponent} from '../bakerecordedit/bakerecordedit.component';
import {AdminService} from "../../../../services/admin.service";
import {AlertService} from "../../../../services/alert.service";

@Component({
  selector: 'app-bakerecordlist',
  templateUrl: './bakerecordlist.component.html',
  styleUrls: ['./bakerecordlist.component.css']
})
export class BakerecordlistComponent implements OnInit {
  rl:Array<BakeRecord>;
  constructor(private modal: NzModalService, private viewContainerRef: ViewContainerRef,
              private adminService:AdminService,private alertService:AlertService) {
    this.rl=new Array<BakeRecord>();
    this.initData();
  }

  ngOnInit(): void {
    this.initData();
  }


  initData(){
   this.adminService.getBakerecord().then((data:any)=>{
     if(data.msg == "ok"){
       this.rl = data.list
     }else{
       this.alertService.showError("获取烘焙生产记录失败")

     }
   })
  }

  record(id:string){
    const modalwindow= this.modal.create({
      nzTitle: '烘培生产信息编辑',
      nzContent: BakerecordeditComponent,
      nzViewContainerRef: this.viewContainerRef,
      nzComponentParams: {
      id:id
      },

      nzOnOk:()=>new Promise(resolve => {
        let temp=modalwindow.getContentComponent().b;
        if(!temp.hbrq){
          this.alertService.showWarning('烘焙日期必填');
          resolve(false)
        }else if(!temp.hbl){
          this.alertService.showWarning('烘焙量必填');
          resolve(false)
        }else if(!temp.csl){
          this.alertService.showWarning('产出量必填');
          resolve(false)
        } else if(!temp.rdwd){
          this.alertService.showWarning('入豆温度必填');
          resolve(false)
        }else if(!temp.ybwd){
          this.alertService.showWarning('一爆温度必填');
          resolve(false)
        }else if(!temp.ybsj){
          this.alertService.showWarning('一爆时间必填');
          resolve(false)
        }else if(!temp.cdwd){
          this.alertService.showWarning('出豆温度必填');
          resolve(false)
        }else if(!temp.hbsj){
          this.alertService.showWarning('烘焙时间必填');
          resolve(false)
        }else if(!temp.fm){
          this.alertService.showWarning('风门必填');
          resolve(false)
        }
        else {
          modalwindow.getContentComponent().save();
          setTimeout(()=>{

            resolve(true);

            this.initData();

          }, 1000)
        }

      })
    })
  }

getBakerecordListByClqk(c:string){
    this.adminService.getBakerecordsByClqk(c).then((data:any)=>{
      if(data.msg == "ok"){
        this.rl = data.list
      }else{
        this.alertService.showError("根据处理情况查询烘焙生产错误")
      }
    })
}


}
